hallatore氏改良版DPM++ 2M Karras
彩度を少し犠牲にする代わりに滑らかな画像を出力できる
比較画像
$ ~~\stable-diffusion-webui\repositories\k-diffusion\k_diffusion\sampling.py
の一番下に次のコードをコピペする
code:DPM++ 2M Karras v2.py
@torch.no_grad()
def sample_dpmpp_2mV2(model, x, sigmas, extra_args=None, callback=None, disable=None):
"""DPM-Solver++(2M) V2."""
extra_args = {} if extra_args is None else extra_args
s_in = x.new_ones([x.shape0]) sigma_fn = lambda t: t.neg().exp()
t_fn = lambda sigma: sigma.log().neg()
old_denoised = None
for i in trange(len(sigmas) - 1, disable=disable):
denoised = model(x, sigmasi * s_in, **extra_args) if callback is not None:
callback({'x': x, 'i': i, 'sigma': sigmasi, 'sigma_hat': sigmasi, 'denoised': denoised}) t, t_next = t_fn(sigmasi), t_fn(sigmasi + 1) h = t_next - t
if old_denoised is None or sigmasi + 1 == 0: x = (sigma_fn(t_next) / sigma_fn(t)) * x - (-h).expm1() * denoised
else:
h_last = t - t_fn(sigmasi - 1) r = h_last / h
denoised_d = (1 + 1 / (2 * r)) * denoised - (1 / (2 * r)) * old_denoised
x = (sigma_fn(t_next) / sigma_fn(t)) * x - (-h).expm1() * denoised_d
sigma_progress = i / len(sigmas)
adjustment_factor = 1 + (0.15 * (sigma_progress * sigma_progress))
old_denoised = denoised * adjustment_factor
return x
$ ~~\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py
29行目の下に以下を追加する
code:DPM++ 2M Karras v2
('DPM++ 2M Karras v2', 'sample_dpmpp_2mV2', 'k_dpmpp_2m_ka', {'scheduler': 'karras'}), https://gyazo.com/dd4171781db1d2d22419bc370c75c216